package com.wdg.controller;

import com.wdg.pojo.*;
import com.wdg.service.IIndexService;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/provider_index")
public class IndexController {

    @Autowired
    private IIndexService indexService;

    //今日推荐，根据推荐表查出
    @GetMapping("/getCookBookForIndex")
    List<TodayRecommend> getCookBookForIndex(){
        List<TodayRecommend> cookBookForIndex = indexService.getCookBookForIndex();
        System.out.println(cookBookForIndex);
        return cookBookForIndex;
    }

    //轮播图，根据轮播表查出
    @GetMapping("/getCircleImageForIndex")
    List<CircleImage> getCircleImageForIndex(){
        return indexService.getCircleImageForIndex();
    }

    //最新菜谱,根据上传时间查出
    @GetMapping("/getNewCookBookForIndex")
    List<Cookbook> getNewCookBookForIndex(){
        return indexService.getNewCookBookForIndex();
    }

    //热门分类,随机查询分类展示
    @GetMapping("/getHotFoodForIndex")
    List<Food> getHotFoodForIndex(){
        return indexService.getHotFoodForIndex();
    }

    //    根据cbid查询这一个菜谱的所以信息
    @GetMapping("/getCookBookByCbid/{cbid}")
    Cookbook getCookBookByCbid(@PathVariable("cbid") String cbid){

        Cookbook cookBookByCbid = indexService.getCookBookByCbid(cbid);

        cookBookByCbid.setOrdertime(cookBookByCbid.getOrdertime().split(" ")[0]);

        return cookBookByCbid;
    }
//增加菜谱浏览量
    @GetMapping("addCookBookView/{cbid}")
    void addCookBookView(@PathVariable("cbid") String cbid){
        indexService.addCookBookView(cbid);
    }

//    查询分类

    @GetMapping("/getAllSort")
    public List<Foodtitle> getAllSort() {
        return indexService.getAllSort();
    }
//根据分类查找所有的菜谱
    @GetMapping("/getCookBookByFid/{fid}")
    public List<Sort> getCookBookByFid(@RequestParam("fid") int fid, @RequestParam("pageId") int pageId) {
        System.out.println(fid);
        return indexService.getCookBookByFid(fid,pageId);
    }

}
